/*==============================================================*/
/* DBMS name:      Microsoft SQL Server 2005                    */
/* Created on:     2011/7/8 11:15:35                            */
/*==============================================================*/


if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('DTL_Tasks') and o.name = 'FK_DTL_TASK_REFERENCE_DTL_USER')
alter table DTL_Tasks
   drop constraint FK_DTL_TASK_REFERENCE_DTL_USER
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('DTL_Tasks') and o.name = 'FK_DTL_TASK_REFERENCE_DTL_PROJ')
alter table DTL_Tasks
   drop constraint FK_DTL_TASK_REFERENCE_DTL_PROJ
go

if exists (select 1
            from  sysobjects
           where  id = object_id('DTL_FeedBack')
            and   type = 'U')
   drop table DTL_FeedBack
go

if exists (select 1
            from  sysobjects
           where  id = object_id('DTL_Projects')
            and   type = 'U')
   drop table DTL_Projects
go

if exists (select 1
            from  sysobjects
           where  id = object_id('DTL_Tasks')
            and   type = 'U')
   drop table DTL_Tasks
go

if exists (select 1
            from  sysobjects
           where  id = object_id('DTL_Users')
            and   type = 'U')
   drop table DTL_Users
go

/*==============================================================*/
/* Table: DTL_FeedBack                                          */
/*==============================================================*/
create table DTL_FeedBack (
   Id                   int                  identity,
   UserName             varchar(30)          null,
   UserQQ               varchar(30)          null,
   Title                varchar(50)          null,
   Content              varchar(1000)        null,
   AddTime              datetime             null,
   IsLock               int                  not null,
   ReContent            varchar(1000)        null,
   ReTime               datetime             null,
   constraint PK_DTL_FEEDBACK primary key (Id)
)
go

/*==============================================================*/
/* Table: DTL_Projects                                          */
/*==============================================================*/
create table DTL_Projects (
   Id                   int                  not null,
   PjtName              varchar(50)          null,
   PjtDescription       varchar(300)         null,
   PjtUrl               varchar(300)         null,
   constraint PK_DTL_PROJECTS primary key (Id)
)
go

/*==============================================================*/
/* Table: DTL_Tasks                                             */
/*==============================================================*/
create table DTL_Tasks (
   Id                   int                  not null,
   PrjId                int                  null,
   TskName              varchar(50)          null,
   TskDescription       ntext                null,
   TskStatus            int                  null,
   TskFixUserId         int                  null,
   TskFixedComment      ntext                null,
   constraint PK_DTL_TASKS primary key (Id)
)
go

/*==============================================================*/
/* Table: DTL_Users                                             */
/*==============================================================*/
create table DTL_Users (
   Id                   int                  not null,
   UserName             varchar(50)          null,
   UserPwd              varchar(50)          null,
   NickName             varchar(50)          null,
   UserRole             int                  null,
   UserEmail            varchar(50)          null,
   constraint PK_DTL_USERS primary key (Id)
)
go

alter table DTL_Tasks
   add constraint FK_DTL_TASK_REFERENCE_DTL_USER foreign key (TskFixUserId)
      references DTL_Users (Id)
go

alter table DTL_Tasks
   add constraint FK_DTL_TASK_REFERENCE_DTL_PROJ foreign key (PrjId)
      references DTL_Projects (Id)
go

